package tau.dimes.visualization.applet.topology;

import java.util.ArrayList;

import tau.dimes.visualization.applet.Parameters;

/**
 * Represents a trace (ordered list of arcs) in the topology visualization.
 */
public class TopologyTrace
{
	private final ArrayList<TopologyArc> arcs;

	/**
	 * Constructs a new TopologyTrace.
	 */
	public TopologyTrace()
	{
		this.arcs = new ArrayList<TopologyArc>();
	}

	/**
	 * Adds a new arc to the trace.
	 * @param arc Arc instace to add to the trace.
	 */
	public void addArc(TopologyArc arc)
	{
		arcs.add(arc);
	}

	/**
	 * Draws the graphical representation of the arc.
	 * @param timeSlot Time slot index.
	 * @param alpha Alpha value (see Clock class).
	 */
	public void draw(int timeSlot, float alpha)
	{
		int index = Math.min(timeSlot, arcs.size());
		int window = Parameters.getWindow();
		
		for (int i = 0; i <= index; i++)
		{
			if (i < index - window)
				arcs.get(i).draw(ArcDrawStage.Deleted, alpha);
			else if (i == index - window && timeSlot < arcs.size())
				arcs.get(i).draw(ArcDrawStage.Deleting, alpha);
			else if (i < index)
				arcs.get(i).draw(ArcDrawStage.Full, alpha);
			else if (i == index && timeSlot < arcs.size())
				arcs.get(i).draw(ArcDrawStage.Drawing, alpha);
		}
	}
}